package com.arceus.leetcode;

/**
 * @author : iron
 * @version : 1.0.0
 * @date : 3:07 PM 2018/12/20
 */

public class T844 {

    public static void main(String[] args) {

        String s = "21312312";
        System.out.println(searchAllIndex(s, "1"));
    }

    private static String searchAllIndex(String str, String key) {
        //*第一个出现的索引位置
        int a = str.indexOf(key);
        StringBuffer stringBuffer = new StringBuffer(str);
        while (a != -1) {
            //*从这个索引往后开始第一个出现的位置
            a = str.indexOf(key, a + 1);
            String tmpString = "";
            tmpString += key;

            int iFlag = -1;
            do {
                iFlag = stringBuffer.indexOf(tmpString);
                if (iFlag != -1) {
                    stringBuffer.deleteCharAt(iFlag);
                    if (iFlag - 1 >= 0) {
                        stringBuffer.deleteCharAt(iFlag - 1);
                    }
                }
            } while (iFlag != -1);
        }
        return stringBuffer.toString();
    }
}
